<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
    <div id="app">
        <div class="content-header">
            <h1>预约管理<small>检查项管理</small></h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                <el-breadcrumb-item>检查项管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="app-container">
            <div class="box">
                <div class="filter-container">
                    <el-input placeholder="项目编码/项目名称" v-model="pagination.queryString" style="width: 200px;"
                              class="filter-item"></el-input>
                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                </div>
                <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="name" label="体检人姓名" align="center"></el-table-column>
                    <el-table-column prop="setmealname" label="套餐" align="center"></el-table-column>
                    <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                    <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                    <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                </el-table>
                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>
                <!-- 新增标签弹层 -->
                <!--                新增弹框区域-->
                <div class="add-form">
                    <el-dialog title="新增检查项" v-if="dialogFormVisible" :visible.sync="dialogFormVisible">
                        <el-form :rules="rules" :model="formData" ref="addForm" label-position="right"
                                 label-width="100px">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="体检人" prop="name">
                                        <el-input v-model="formData.name"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="手机" prop="telephone">
                                        <el-input v-model="formData.telephone"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-form-item label="性别" prop="sex">
                                <el-select v-model="formData.sex">
                                    <el-option value="1" label="男"></el-option>
                                    <el-option value="0" label="女"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="身份证号码" prop="idCard">
                                <el-input v-model="formData.idCard"></el-input>
                            </el-form-item>
                            <el-form-item label="套餐" prop="setmealId">
                                <el-select v-model="formData.setmealId">
                                    <el-option v-for="item in selectData" :label="item.name" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="体检日期" prop="orderDate">
                                <template>
                                    <div class="block">
                                        <span class="demonstration"></span>
                                        <el-date-picker
                                                v-model="formData.orderDate"
                                                type="date"
                                                placeholder="选择日期"
                                                :picker-options="pickerOptions"
                                        >
                                        </el-date-picker>
                                    </div>
                                </template>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible = false">取消</el-button>
                            <el-button type="primary" @click="handleAdd()">确定</el-button>
                        </div>
                    </el-dialog>
                </div>


            </div>
        </div>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../vue/healthmobile.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            selectData: [],//套餐选择
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '请输入姓名', trigger: 'blur'}],
                telephone: [{required: true, message: '请输入手机号码', trigger: 'blur'},
                    {
                        validator: (rule, value, callback) => {
                            //当前框里面输入的值
                            //校验框架的回调
                            if (checkTelephone(value)) {
                                callback();//校验成功就不填
                            } else {
                                callback("手机号码格式不正确");//校验失败就传入提示信息
                            }
                        }
                    }
                ],
                idCard: [{required: true, message: '请输入身份证号码', trigger: 'blur'},
                    {
                        validator: (rule, value, callback) => {
                            //当前框里面输入的值
                            //校验框架的回调
                            if (checkIdCard(value)) {
                                callback();//校验成功就不填
                            } else {
                                callback("身份证号码格式不正确");//校验失败就传入提示信息
                            }
                        }
                    }
                ],
                setmealId:[{required: true, message: '请选择套餐', trigger: 'change'}],
                sex:[{required: true, message: '请选择性别', trigger: 'change'}],
                orderDate:[{required: true, message: '请选择日期', trigger: 'blur'}]
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now();
                }
            }
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd() {
                this.$refs.addForm.validate((flag) => {
                    if (flag) {
                        console.log(this.formData);
                        axios.post("/checkOrderList/add.do", this.formData).then((res) => {
                            if (res.data.flag) {
                                //关闭弹框
                                this.dialogFormVisible = false;
                                //刷新页面
                                this.findPage();
                            }
                            //提示用户
                            this.$message({
                                message: res.data.message,
                                type: res.data.flag ? "success" : "error"
                            });
                        }).catch((error) => {
                            console.log(error);
                        })
                    } else {
                        //校验失败
                        this.$message({
                            message: '表单校验失败',
                            type: 'error'
                        });
                    }
                });
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,//页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    queryString: this.pagination.queryString //查询条件
                };
                //请求后台
                axios.post("/checkOrderList/findPage.do", param).then((response) => {
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                })
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                //查询套餐到下拉框供小护士选择
                axios.get("/checkOrderList/findAll.do").then((res) => {
                    this.selectData = res.data.data;
                    //弹出新增的框
                    this.dialogFormVisible = true;
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //改变pagination.currentPage
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
        }
    })
</script>
</html>